<?php
/**
 * publishcontroll.php
 * Create on 2015-03-31 14:32:57
 * Create by yuebin
 */
namespace haibao\cms\business\control;

use haibao\frame\data\query\Condition;
use haibao\cms\model\filter\site\SiteChannelTemplate as SiteChannelTemplateFilter;
use haibao\cms\model\filter\site\PageTemplate as PageTemplateFilter;
use haibao\cms\model\filter\site\SiteChannelTag as SiteChannelTagFilter;
use haibao\cms\model\filter\site\SiteChannel as SiteChannelFilter;
use haibao\cms\business\site\SiteChannel;

class PublishController extends \haibao\cms\business\Base{

	const NO_STRUCTURE_TAG = 6;
	
	private static $cacheControlList= array();
	private static $isPublish;
	private static $updateTime;
	private static $currentPage;
	private static $pageable;// 提供给发布时候使用
	private static $siteTemplateId;//站点关联模版ID（用于分页拼接Url）
	private static $siteChannelTag;//站点频道标签
	private static $fileName;//文件保存路径
	private static $tagInfo = '';//标签信息
	private static $isPregTDK = false;
	private static $channelId = 0 ;//站点频道ID
	
	/**
	 * 获取模版（预览/发布）
	 * @param : $id 模版关联ID
	 * @param : $isPublish 是否发布
	 * @param : $currentPage 当前第几页 提供给预览使用参数
	 */
	public static function getTemplateById($id,$isPublish = false,$currentPage = 1){
		
		self::$isPublish = $isPublish;
		self::$currentPage = $currentPage;
		$publishInfo = self::getSiteChannelTmpById($id);
		if($publishInfo->TemplateInfo->Content){
			
			self::$siteTemplateId = $id;
			self::$pageable = $publishInfo->TemplateInfo->Pageable;
			self::$siteChannelTag = $publishInfo->SiteChannelTag->TagId;
			self::$fileName = $publishInfo->FileName;
			self::$channelId = $publishInfo->ChannelId;
			
			$content = $publishInfo->TemplateInfo->Content;
			$content = self::replaceHeadInfo($content);
			self::$isPregTDK = false;
			$content = self::replaceDynamicData($content);
			
			$html = self::parseTemplateContent($content,$publishInfo->TemplateInfo->UpdateTime->format('Y-m-d H:i:s'));
		}
		if($isPublish){
			return array($publishInfo->FileName,$html);
		}
		return $html;
	}
	
	/**
	 * 根据模版内容获取模版静态页
	 * @param : $content 模版内容
	 * @param : $isPublish 是否发布
	 * @param : $currentPage 当前第几页 提供给预览使用参数
	 */
	public static function getTemplateByContent($content,$updateTime,$isPublish = false,$currentPage = 1){
	
		self::$isPublish = $isPublish;
		self::$currentPage = $currentPage;
		
		$content = self::replaceHeadInfo($content);
		$html = self::parseTemplateContent($content,$updateTime);
		/* if(strlen($content) < 10000){
			file_put_contents(\haibao\frame\Environment::path().'/web/logs/migrate.log', '------------finalHtml = '.$html."\n",FILE_APPEND);
		} */
		return $html;
	}

	/**
	 * 根据标签ID获取模版静态页面
	 */
	public static function getTemplateByTagId($tagId,$currentPage = 1){
		
		self::$isPublish = true;
		self::$currentPage = $currentPage;
		
		$publishInfo = self::getSiteChannelTmpById(\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::TAG_LIST_DIE_TEMPLATE));
		if($publishInfo->TemplateInfo->Content){
				
			self::$siteTemplateId = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::TAG_LIST_DIE_TEMPLATE);
			self::$pageable = $publishInfo->TemplateInfo->Pageable;
			self::$siteChannelTag = $tagId;
			self::$fileName = $publishInfo->FileName;
				
			$content = $publishInfo->TemplateInfo->Content;
			$content = self::replaceHeadInfo($content);
			$content = self::replaceDynamicData($content);
				
			$html = self::parseTemplateContent($content,$publishInfo->TemplateInfo->UpdateTime->format('Y-m-d H:i:s'));
		}
		return $html;
	}
	/**
	 * 根据标签ID获取模版静态页面
	 */
	public static function getTemplateContentByType($type,$currentPage = 1){
	
	    self::$isPublish = true;
	    self::$currentPage = $currentPage;
	    if($type == 1){
	        $tmpId = 40;
	    }else{
	        $tmpId = 41;
	    }
	    $publishInfo = self::getSiteChannelTmpById($tmpId);
	    if($publishInfo->TemplateInfo->Content){
	
	        self::$siteTemplateId = $tmpId;
	        self::$pageable = $publishInfo->TemplateInfo->Pageable;
	        self::$fileName = $publishInfo->FileName;
	
	        $content = $publishInfo->TemplateInfo->Content;
	        $content = self::replaceHeadInfo($content);
	        $content = self::replaceDynamicData($content);
	
	        $html = self::parseTemplateContent($content,$publishInfo->TemplateInfo->UpdateTime->format('Y-m-d H:i:s'));
	    }
	    return $html;
	}
	
	/**
	 * 根据channelCode获取模版内容
	 */
	public static function getTemplateContentByChannelCode($channelCode,$isPublish = false,$currentPage = 1,$tagId = 0){
		self::$isPublish = $isPublish;
		self::$currentPage = $currentPage;
		$publishInfo = self::getSiteChannelTmpByChannelCode($channelCode);
		if($publishInfo && $publishInfo->SiteChannelTemplate->TemplateInfo){
			self::$siteTemplateId = $publishInfo->SiteChannelTemplate->Id;
			self::$pageable = $publishInfo->SiteChannelTemplate->TemplateInfo->Pageable;
			self::$fileName = $publishInfo->SiteChannelTemplate->FileName;
			self::$channelId = $publishInfo->Id;

			$content = self::getSpecialTagTemplateContent($channelCode, $tagId, $publishInfo);//$publishInfo->SiteChannelTemplate->TemplateInfo->Content;
			$content = self::replaceHeadInfo($content);
			self::$isPregTDK = false;
			if($tagId){
				self::$siteChannelTag = $tagId;
			}
			$content = self::replaceDynamicData($content);
			$html = self::parseTemplateContent($content,$publishInfo->SiteChannelTemplate->TemplateInfo->UpdateTime->format('Y-m-d H:i:s'));
		}
		if($isPublish){
			return array($publishInfo->SiteChannelTemplate->FileName,$html);
		}
		return $html;
	}

	private static function getSpecialTagTemplateContent($channelCode,$tagId,$publishInfo){
		$content = $publishInfo->SiteChannelTemplate->TemplateInfo->Content;
		if($channelCode == \haibao\cms\business\site\SiteChannel::SPECIAL_TAG_LIST){
			$contentPathSVN = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::SITE_PAGE_TEMPLATE_PATH).'pc/tag/'.$tagId.'.html';
			if(file_exists($contentPathSVN)){
				$content = file_get_contents($contentPathSVN);
			}
		}
		return $content;
	}
	
	/**
	 * 解析模版内容 （此方法存在递归使用 所以将正则匹配单独拆一个私有方法）
	 * @param : String $content 模版内容
	 */
	private static function parseTemplateContent($content,$updateTime){
		$templateContent = self::regTemplateContentNew($content,$updateTime);
		return $templateContent;
	}
	
	/**
	 * 正则替换文本中包含<controller data=\"(.*)\">内容
	 * @param String $content 文本内容
	 * @param DateTime $updateTime
	 */
	private static function regTemplateContentNew($content,$updateTime){
		self::$updateTime = $updateTime;
		$pattern = '/<controller data=(?:\'|\")(.*)(?:\'|\")>/isU';
		
		$content = preg_replace_callback($pattern,'self::replaceCallback',$content);
		return $content;
	}
	
	/**
	 * 正则方法回调
	 */
	private static function replaceCallback($matches){
		$html = '';
		$controlData = json_decode($matches[1],true);
		$controlList = self::getPageControlById($controlData['id']);
		if($controlList && !empty($controlList[$controlData['id']])){
			$controlInfo = $controlList[$controlData['id']];
			if($controlInfo && $controlInfo->Content){
				if(class_exists($controlInfo->Controller)){
					// DO : 解析控件数据
					$controlDatas = self::parseControlData($controlData);
		
					$cls = new $controlInfo->Controller(self::$updateTime,$controlData['id'],self::$isPublish);
					self::packageParameter($cls,$controlDatas,$controlInfo->Content);
			
					$templateContent = $cls->displayTemplateHtml();
					 
					// DO : 替换控件数据为真实模版数据
					$html = self::regTemplateContentNew($templateContent,self::$updateTime);
				}
			}
		}
		
		return $html;
	}
	
	/**
	 * 封装控制器需要的参数
	 */
	private static function packageParameter($cls,$data,$content){
		

		$content = self::replaceHeadInfo($content);
		self::$isPregTDK = true;
		$cls->setParameter('controlData',$data);
		$cls->setParameter('content',self::replaceDynamicData($content));
		$cls->setParameter('currentPage',self::$currentPage);
		$cls->setParameter('pageable',self::$pageable);
		$cls->setParameter('siteTemplateId',self::$siteTemplateId);
		$cls->setParameter('siteChannelTag',self::$siteChannelTag);
		$cls->setParameter('fileName',self::$fileName);
		$cls->setParameter('tagInfo',self::$tagInfo);
		$cls->setParameter('channelId',self::$channelId);

	}

	/**
	 * 解析控件数据(JSON 格式) 手动/自动
	 * @param : String $controlData
	 */
	private static function parseControlData($controlData){
		
		$autoDataArr = $manualDataArr = $controlDataArry = array();
		if($controlData['id']){
			
			$controlDataId = $controlData['id'];
			$controlDataList = self::getPageControlDataByControlId($controlDataId);
			if($controlDataList){
				foreach($controlDataList as $list){
					array_push($autoDataArr,$list->toArray());
				}
			}
		}
		if(count($controlData) > 1){
			$manualDataArr = $controlData;
		}
		$controlDataArry['auto'] = $autoDataArr;
		$controlDataArry['manual'] = $manualDataArr;
		return $controlDataArry;
	}
	

	/**
	 * 获取站点频道模版数据
	 * @param : Int $id
	 */
	private static function getSiteChannelTmpById($id){
		$siteChannelTemplateFilter = new SiteChannelTemplateFilter;
		$siteChannelTemplateFilter->select(
				array(
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_ID,
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_ID,
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_CHANNEL_ID,
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_AUTO_BUILD,
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_BUILD_CYCLE,
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_FILE_NAME,
				)
		);
		$pageTemplateFilter = new PageTemplateFilter();
		$pageTemplateFilter->select(
				array(
						PageTemplateFilter::CONDITION_FIELD_NAME_ID,
						PageTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_NAME,
						PageTemplateFilter::CONDITION_FIELD_NAME_CONTENT,
						PageTemplateFilter::CONDITION_FIELD_NAME_UPDATE_TIME,
						PageTemplateFilter::CONDITION_FIELD_NAME_PAGEABLE,
						PageTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_PATH,
				)
		);
		$siteChannelTagFilter = new SiteChannelTagFilter();
		$siteChannelTagFilter->select(
				array(
						SiteChannelTagFilter::CONDITION_FIELD_NAME_TAG_ID
				)
		);
		
		$siteChannelTemplateFilter->leftJoin($pageTemplateFilter,null,SiteChannelTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_ID,PageTemplateFilter::CONDITION_FIELD_NAME_ID,SiteChannelTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_INFO,false);
		$siteChannelTemplateFilter->leftJoin($siteChannelTagFilter,null,SiteChannelTemplateFilter::CONDITION_FIELD_NAME_CHANNEL_ID,SiteChannelTagFilter::CONDITION_FIELD_NAME_CHANNEL_ID,SiteChannelTemplateFilter::CONDITION_FIELD_NAME_SITE_CHANNEL_TAG,false);
		
		$siteChannelTemplateFilter->where(SiteChannelTemplateFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_EQUAL,$id);
		
		$data = new \haibao\cms\data\site\SiteChannelTemplate();
		$siteChannel = $data->getOne($siteChannelTemplateFilter);
		if($siteChannel->TemplateInfo->TemplatePath){
			$contentPathSVN = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::SITE_PAGE_TEMPLATE_PATH).$siteChannel->TemplateInfo->TemplatePath;
			if(file_exists($contentPathSVN)){
				$siteChannel->TemplateInfo->Content = file_get_contents($contentPathSVN);
			}
		}
		return $siteChannel;
	}
	/**
	 * 根据channelCode获取站点信息
	 * @param : String $channelCode
	 */
	private static function getSiteChannelTmpByChannelCode($channelCode){
		
		$siteChannelFilter = new SiteChannelFilter();
		$siteChannelFilter->select(array(
			SiteChannelFilter::CONDITION_FIELD_NAME_ID
			)
		);
		$siteChannelTemplateFilter = new SiteChannelTemplateFilter;
		$siteChannelTemplateFilter->select(
				array(
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_ID,
						SiteChannelTemplateFilter::CONDITION_FIELD_NAME_FILE_NAME,
				)
		);
		$pageTemplateFilter = new PageTemplateFilter();
		$pageTemplateFilter->select(
				array(
						PageTemplateFilter::CONDITION_FIELD_NAME_CONTENT,
						PageTemplateFilter::CONDITION_FIELD_NAME_PAGEABLE,
						PageTemplateFilter::CONDITION_FIELD_NAME_UPDATE_TIME,
						PageTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_PATH,
				)
		);
		$siteChannelFilter->limit(0,1);
		$siteChannelFilter->order(SiteChannelFilter::CONDITION_FIELD_NAME_ID,false);
		$siteChannelFilter->where(SiteChannelFilter::CONDITION_FIELD_NAME_CHANNEL_CHANNEL_CODE,Condition::CONDITION_EQUAL,$channelCode);
		$siteChannelFilter->innerJoin($siteChannelTemplateFilter,null,SiteChannelFilter::CONDITION_FIELD_NAME_ID,SiteChannelTemplateFilter::CONDITION_FIELD_NAME_CHANNEL_ID,SiteChannelFilter::CONDITION_FIELD_NAME_CHANNEL_SITE_CHANNEL_TEMPLATE,false);
		$siteChannelFilter->innerJoin($pageTemplateFilter,$siteChannelTemplateFilter,SiteChannelTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_ID,PageTemplateFilter::CONDITION_FIELD_NAME_ID,SiteChannelTemplateFilter::CONDITION_FIELD_NAME_TEMPLATE_INFO,false);
		$data = new \haibao\cms\data\site\SiteChannel();
		$siteChannel = $data->getOne($siteChannelFilter);
		if($siteChannel && $siteChannel->SiteChannelTemplate->TemplateInfo->TemplatePath){
			$contentPathSVN = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::SITE_PAGE_TEMPLATE_PATH).$siteChannel->SiteChannelTemplate->TemplateInfo->TemplatePath;
			if(file_exists($contentPathSVN)){
				$siteChannel->SiteChannelTemplate->TemplateInfo->Content = file_get_contents($contentPathSVN);
			}
		}
		return $siteChannel;
	}
	
	/**
	 * 获取控件基本数据
	 * @param : Array $controlIdArr 控件ID
	 */
	private static function getPageControlById($controlId){
		
		if(!isset(self::$cacheControlList[$controlId])){
			$controlFilter = new \haibao\cms\model\filter\PageControl();
			$controlFilter->select(
				array(
					\haibao\cms\model\filter\PageControl::CONDITION_FIELD_NAME_CONTROLLER,
					\haibao\cms\model\filter\PageControl::CONDITION_FIELD_NAME_CONTENT,
					\haibao\cms\model\filter\PageControl::CONDITION_FIELD_NAME_ID,
					\haibao\cms\model\filter\PageControl::CONDITION_FIELD_NAME_CONTROL_PATH,
				)
			);
			$controlFilter->order(\haibao\cms\model\filter\PageControl::CONDITION_FIELD_NAME_ID,false);
			$controlFilter->where(\haibao\cms\model\filter\PageControl::CONDITION_FIELD_NAME_ID,Condition::CONDITION_EQUAL,$controlId);
			$data = new \haibao\cms\data\PageControl();
			$controlInfo = $data->getOne($controlFilter);
			if($controlInfo->ControlPath){
				$contentPathSVN = \haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::SITE_CONTROL_TEMPLATE_PATH).$controlInfo->ControlPath;
				if(file_exists($contentPathSVN)){
					$controlInfo->Content = file_get_contents($contentPathSVN);
				}
			}
			self::$cacheControlList[$controlId] = $controlInfo;
		}
		return self::$cacheControlList;
	}
	
	/**
	 * 获取控件手动数据
	 * @param : Array $controlIdArr 控件ID
	 */
	public static function getPageControlDataByControlId($controlDataId){
	
		$controlDataFilter = new \haibao\cms\model\filter\PageControlData();
		$controlDataPeriodFilter = new \haibao\cms\model\filter\PageControlDataPeriod();
		$controlDataFilter->select(
			array(
				\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_ID,
				\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_PARAMETER_VALUE,
				\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_DESCRIPTION,
				\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_ORDER_NO,
				\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_CONTROL_ID,
			)
		);
		$controlDataPeriodFilter->select(
			array(
				\haibao\cms\model\filter\PageControlDataPeriod::CONDITION_FIELD_NAME_ID,
				\haibao\cms\model\filter\PageControlDataPeriod::CONDITION_FIELD_NAME_CONTROL_DATA_ID
			)
		);
		$controlDataFilter->order(\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_ORDER_NO);
		$controlDataFilter->order(\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_CREATE_TIME,false);
		$controlDataFilter->where(\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_CONTROL_ID,Condition::CONDITION_EQUAL,$controlDataId);
		$controlDataFilter->where(\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\PageControlData::STATUS_ON_LINE);
		
		$controlDataFilter->leftJoin($controlDataPeriodFilter,null,\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_ID,\haibao\cms\model\filter\PageControlDataPeriod::CONDITION_FIELD_NAME_CONTROL_DATA_ID,\haibao\cms\model\filter\PageControlData::CONDITION_FIELD_NAME_PERIODS);
		//$controlDataPeriodFilter->where(\haibao\cms\model\filter\PageControlDataPeriod::CONDITION_FIELD_NAME_START_TIME,Condition::CONDITION_LESSEQUAL,new \DateTime());
		//$controlDataPeriodFilter->where(\haibao\cms\model\filter\PageControlDataPeriod::CONDITION_FIELD_NAME_END_TIME,Condition::CONDITION_GREATEREQUAL,new \DateTime());
		
		$data = new \haibao\cms\data\PageControl();
		return $data->getAll($controlDataFilter);
	}
	
	/**
	 * 替换模版头部样式引入地址
	 */
	private static function replaceHeadInfo($content){
		
		$domainHost = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_STATIC_DOMAIN);
		if(\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_CDN_DEFAULT)){
			$domainHost = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_CDN_DOMAIN);
		}
		$pattern = '/{\$staticHost}/isU';
		$content = preg_replace($pattern,$domainHost,$content);
		
		$pattern = '/{\$currentYear}/isU';
		$content = preg_replace($pattern,date('Y'),$content);
		
		$pattern = '/{\$s1Host}/isU';
		$content = preg_replace($pattern,\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_STATIC_ONE_DOMAIN),$content);
		
		$pattern = '/{\$staticVersion}/isU';
		$content = preg_replace($pattern,\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_STATIC_VERSION),$content);
		
		$pattern = '/{\$userHost}/isU';
		$content = preg_replace($pattern,\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_USER),$content);
		$pattern = '/{\$wwwHost}/isU';
		$content = preg_replace($pattern,\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HAIBAO_URL),$content);
		
		$pattern = '/{\$adHost}/isU';
		$content = preg_replace($pattern,\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_AD),$content);
		return $content;
	}

	/**
	 * 替换模版需要的一些动态
	 * 避免<controller *> 参数为死数据
	 */
	private static function replaceDynamicData($content){

		if( self::$pageable > \haibao\cms\model\data\site\PageTemplate::PAGEABLE_NONE){
			if(!self::$isPregTDK ) {
				$content = self::pregTDK($content);
			}
			if(self::$tagInfo){
				$patterns = array();
				array_push($patterns,'/preg:tagIds/i');
				array_push($patterns,'/preg:topTagId/i');
				
				$replacements = array();
				array_unshift($replacements,self::$tagInfo->TopId);
				array_unshift($replacements,self::$siteChannelTag);
				
				$content = preg_replace($patterns,$replacements,$content);
			}
		}
		return $content;
	}
	
	/**
	 * 添加模版文件TDK
	 */
	private static function pregTDK($content){
		self::$tagInfo = \haibao\cms\business\Tag::getTagById(self::$siteChannelTag,false);
		if(self::$tagInfo){
			$channel = '';
			$title = $keywords = $description = '海报时尚网';
			/**
			 * 1  如果标签ID就是顶级标签TDK表示Right Now
			 * 2  如果为普通标签ID 就表示标签资讯列表页
			 * 3 如果标签为11175,11176,11177,11178,11179 表示自媒体分类
			 */

			$blogTagId = array_map('array_pop', \haibao\cms\business\control\pc\channel\blog\BlogController::getCateInfo(0));
			//$tvTagId = \haibao\cms\business\control\AmericanController::$cateInfo;
			if(in_array(self::$siteChannelTag,$blogTagId)){
				$blogTagId = array_flip(array_filter($blogTagId));
				if($blogTagId[self::$siteChannelTag]==91){
					$title = "【图】自媒体精英专栏Fashion We Media_时尚博主_海报时尚网";
					$keywords = "时尚博主,专家达人,自媒体,we media,时装,美容护肤,海报时尚网";
					$description = "阿治老师，小P老师都是时尚圈子中的名人，专家级的人物，在微博中有众多的粉丝。海报时尚网致力为报友提供更有价值的内容，自媒体精英就是时尚领域的带头人";
					$slideShow = 86;
				}elseif($blogTagId[self::$siteChannelTag]==92){
					$title = "【图】明星、名模博主_时尚博主_海报时尚网";
					$keywords = "明星,名模,模特,超模,明星街拍,明星自拍,明星穿着,明星装扮,时装秀,秀场图片,模特街拍,海报时尚网";
					$description = "海报网签约奚梦瑶等国内国际超级名模和一线明星入驻，关注明星和超模的街拍图片、时尚穿着和装扮，明星就在我们身边。";
					$slideShow = 87;
				}elseif($blogTagId[self::$siteChannelTag]==93){
					$title = "【图】时装博主晒潮流服饰搭配_时尚博主_海报时尚网";
					$keywords = "时装博主,服饰搭配,时装趋势,潮搭街拍,博主自拍,海报时尚网";
					$description = "时尚潮人必然都是懂得穿衣搭配的达人，这里有很多的时装博主与报友分享四季的穿衣经验，引领潮流服饰搭配趋势。";
					$slideShow = 88;
				}elseif($blogTagId[self::$siteChannelTag]==94){
					$title = "【图】美容博主介绍美妆护肤技巧和化妆品牌_时尚博主_海报时尚网";
					$keywords = "美容博主,美容护肤,化妆品品牌,美妆技巧,护肤宝典,美容经验分享,唇彩,粉底,眼霜,海报时尚网";
					$description = "不同的季节、不同的场合，为自己选择相应的妆容会令你格外的出众和自信，海报时尚网美容博主们为报友分享美妆技巧，护肤心得，教你如何唇彩、眼霜等化妆品。";
					$slideShow = 89;
				}elseif($blogTagId[self::$siteChannelTag]==95){
					$title = "【图】摄影师、化妆师、造型师、设计师带来的视觉盛宴_时尚博主_海报时尚网";
					$keywords = "视觉博客,摄影师,化妆师,造型师,设计师,棚拍模特,时尚造型,发型设计,舞台化妆,海报时尚网";
					$description = "欣赏他们的博客就是视觉的盛宴，因为他们的照片张张精彩，资深专业的摄影师、化妆师、造型师、设计师签约海报时尚网博主，为报友介绍他们的作品。";
					$slideShow = 91;
				}
			}elseif(in_array(self::$tagInfo->Id,array(11281,11341,11282,11283,11284))){
			    if(self::$tagInfo->Id==11281){
			        $title = "美剧追踪，最新动态及时更新_海报美剧_海报时尚网";
			        $keywords = "追剧,热剧追踪,美剧最新动态,新剧推荐,预告片花,美剧剧评,原创剧评,欧美综艺,外国综艺节目,海报美剧,海报时尚网";
			        $description = "美剧追踪每天更新热门美剧最新动态，第一时间推荐新剧并配有预告片花，精彩剧评相信会与美剧迷们产生共鸣。美剧相关的最新资讯就在这里。";
			    }elseif(self::$tagInfo->Id==11341){
			        $title = "美剧明星最新动态_海报美剧_海报时尚网";
			        $keywords = "美剧明星,美剧明星最新动态,美剧明星幕后私照,美剧明星街拍,美剧明星库,美剧明星大全,明星星座检索,美剧明星人气排行,海报时尚网";
			        $description = "剧星动态集美剧明星最新动态资讯、幕后私照、街拍、明星库于一体，依托海报时尚网的明星库资源，为美剧明星的粉丝们带来最全的偶像介绍、大图下载。";
			    }elseif(self::$tagInfo->Id==11282){
			        $title = "美剧精彩剧评，欧美电影影评_海报美剧_海报时尚网";
			        $keywords = "最新美剧剧评,经典美剧剧评,热门美剧剧评,欧美电影影评,海报美剧,海报时尚网";
			        $description = "剧评影评栏目为美剧迷提供最热最好看的美剧剧评、欧美电影影评，为大家提供看剧的交流平台。";
			    }elseif(self::$tagInfo->Id==11283){
			        $title = "美剧预告片花视频_海报美剧_海报时尚网";
			        $keywords = "美剧预告片花,新剧预告片,美剧小视频,热门美剧片花剪辑,海报美剧,海报时尚网";
			        $description = "推荐新剧必须配有预告片，让美剧迷们直观感受精彩画面，片花剪辑也可获得拍摄幕后的快乐故事。";
			    }elseif(self::$tagInfo->Id==11284){
			        $title = "欧美影视娱乐圈红毯颁奖盛事_海报美剧_海报时尚网";
			        $keywords = "颁奖典礼,颁奖盛事,获奖美剧,奥斯卡颁奖礼,金球奖颁奖礼,海报时尚网";
			        $description = "欧美电影电视剧的颁奖典礼资讯就在海报美剧红毯颁奖。奥斯卡、金球奖等最新资讯及时为您送达。";
			    }
			    $channel = \haibao\cms\business\control\AmericanController::TV_CHANNEL;
			}elseif(in_array(self::$tagInfo->Id,array(11354,11361,11362,11363,11364,11365,11366,11367))){
			    if(self::$tagInfo->Id==11354){
			        $title = "周公解梦_周公解梦大全免费在线查询_生活_海报时尚网";
			    }elseif(self::$tagInfo->Id==11361){
			        $title = "精彩解梦_周公解梦大全免费在线查询_生活_海报时尚网";
			    }elseif(self::$tagInfo->Id==11362){
			        $title = "梦之物语_周公解梦大全免费在线查询_生活_海报时尚网";
			    }elseif(self::$tagInfo->Id==11363){
			        $title = "风水易经_周公解梦大全免费在线查询_生活_海报时尚网";
			    }elseif(self::$tagInfo->Id==11364){
			        $title = "梦文化_周公解梦大全免费在线查询_生活_海报时尚网";
			    }elseif(self::$tagInfo->Id==11365){
			        $title = "健康睡眠_周公解梦大全免费在线查询_生活_海报时尚网";
			    }elseif(self::$tagInfo->Id==11366){
			        $title = "家居风水解读_周公解梦大全免费在线查询_生活_海报时尚网";
			    }elseif(self::$tagInfo->Id==11367){
			        $title = "办公室风水解读_周公解梦大全免费在线查询_生活_海报时尚网";
			    }
			    $keywords = "梦文化,周公解梦,梦境解析,风水易经,解梦大全,海报时尚网";
			    $description = "海报时尚网提供原版周公解梦大全，为报友解析梦境，指导健康睡眠，家居办公风水。";
			    $channel = \haibao\cms\business\control\JiemengController::JIEMENG_CHANNEL;
			}else{
				if(self::$tagInfo->Id == self::$tagInfo->TopId){
					
					if(self::$tagInfo->Id == self::NO_STRUCTURE_TAG){
						$title = '今日最新_海报时尚网--领先的时尚互动媒体';
						$description = '今日最新资讯';
						$keywords = '今日最新资讯';
					}else{
						$title = self::$tagInfo->TagName.'今日最新_海报时尚网--领先的时尚互动媒体';
						$description = '今日最新资讯';
						$keywords = '今日最新资讯';
					}
				}else{
	
					$title = self::$tagInfo->TagName.'【图】';
					if(self::$currentPage > 1){
						$title .= '_第'.self::$currentPage.'页';
					}
					$title .='_海报时尚网-'.date("Y").'最新'.self::$tagInfo->TagName.'图片资讯';
					$description = mb_substr(strip_tags(self::$tagInfo->Desc),0,100,'utf-8');
					$keywords = self::$tagInfo->TagName.'最新资讯，'.self::$tagInfo->TagName.'最新图片，'.self::$tagInfo->TagName.'，海报网，海报时尚网';
				}
				
				$topTagList = \haibao\cms\business\control\Base::getTopTags();
				if(isset($topTagList[self::$tagInfo->TopId])){
					$channel = $topTagList[self::$tagInfo->TopId]['channel'];
				}
			}
			$patterns = array();
			array_push($patterns,'/\bpreg:title\b/i');
			array_push($patterns,'/\bpreg:description\b/i');
			array_push($patterns,'/\bpreg:keywords\b/i');
			array_push($patterns,'/\bpreg:channel\b/i');
		
			$replacements = array();
			array_unshift($replacements,$channel);
			array_unshift($replacements,$keywords);
			array_unshift($replacements,$description);
			array_unshift($replacements,$title);
		
			$content = preg_replace($patterns,$replacements,$content);
		}
		return $content;
	}
}
